from django.db import models
from ckeditor.fields import RichTextField

class NewsType(models.Model):
    label = models.CharField(max_length=32)
    description = models.TextField()

    def __str__(self):
        return self.label

class Editor(models.Model):
    name = models.CharField(max_length = 32)
    email = models.EmailField()

    def __str__(self):
        return self.name

class News(models.Model):
    title = models.CharField(max_length = 32,verbose_name="新闻标题")
    time = models.DateField()
    description = models.TextField()
    image = models.ImageField(upload_to="img/upload")
    content = models.TextField()
    type_id = models.ForeignKey(to=NewsType,on_delete=models.CASCADE)
    editor_id = models.ManyToManyField(to = Editor)
    # models.CASCADE 级联删除
    # models.SET_NULL 设置为空
    # models.SE_DEFAULT 设置默认值,比如:删除作者,书的作者为佚名

    def __str__(self):
        return self.title

class Foods_type(models.Model):
    label = models.CharField(max_length=32)
    description = models.TextField()

    def __str__(self):
        return self.label

class Foods(models.Model):
    name = models.CharField(max_length=32)
    price = models.FloatField()
    picture = models.ImageField(upload_to='img')
    description = models.TextField()
    type_id = models.ForeignKey(to=Foods_type,on_delete=models.CASCADE)

    def __str__(self):
        return self.name

class NewsNews(models.Model):
    title = models.CharField(max_length=32)
    time = models.DateField
    description = RichTextField()
    image = models.ImageField(upload_to='./about-pic1.jpg')
    content = RichTextField()
    type = models.CharField(max_length=32)

    def __str__(self):
        return self.title

from django.db import models

class Goods(models.Model):
    name = models.CharField(max_length=100)
    des = models.CharField(max_length=1000)
    class Meta:
        db_table = 'goods'

class User(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)
# Create your models here.
